package com.sczmgk.hotline_pzh.ui;

import android.os.Bundle;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.sczmgk.hotline_pzh.R;
import com.sczmgk.hotline_pzh.base.BaseActivity;
import com.sczmgk.hotline_pzh.constants.Constants;

public class ChangeURL extends BaseActivity {
    /**
     * 显示选择当前的URL
     */
    private TextView mUrl;
    /**
     * 选择ur的单选框
     */
    private RadioGroup mSelectURL;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_url);
        setTitle("切换URL");
        initView();
        setListener();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK){
            setResult(RESULT_OK);
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 设置监听
     */

    public void setListener() {


        setLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setResult(RESULT_OK);
                finish();
            }
        });

        mSelectURL.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_cz:
                        Constants.BASE_URL = Constants.chenzhi;
                        mUrl.setText(getString(R.string.base_url,Constants.BASE_URL));
                        break;
                    case R.id.rb_remorte:
                        Constants.BASE_URL = Constants.remorte;
                        mUrl.setText(getString(R.string.base_url,Constants.BASE_URL));
                        break;
                    case R.id.rb_wq:
                        Constants.BASE_URL = Constants.wangqin;
                        mUrl.setText(getString(R.string.base_url,Constants.BASE_URL));
                        break;
                    case R.id.rb_joy:
                        Constants.BASE_URL = Constants.joygov;
                        mUrl.setText(getString(R.string.base_url,Constants.BASE_URL));
                        break;
                    case R.id.rb_jzr:
                        Constants.BASE_URL = Constants.jiangzhenrong;
                        mUrl.setText(getString(R.string.base_url,Constants.BASE_URL));
                        break;
                    case R.id.rb_bobo:
                        Constants.BASE_URL = Constants.bobo;
                        mUrl.setText(getString(R.string.base_url,Constants.BASE_URL));
                        break;
                    case R.id.rb_renhe :
                        Constants.BASE_URL = Constants.renhe;
                        mUrl.setText(getString(R.string.base_url,Constants.BASE_URL));
                        break;
                    default:
                        break;
                }

            }
        });

    }


    private void initView() {
        mSelectURL = (RadioGroup) findViewById(R.id.rg_select_url);
        mUrl = (TextView) findViewById(R.id.tv_base_url);
        mUrl.setText(getString(R.string.base_url, Constants.BASE_URL));

    }


    @Override
    public void handleMessage(Message msg) {

    }

    @Override
    public boolean getIsNeedLogin() {
        return false;
    }
}
